package dk.eclipse.android.helpers;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class XMLHelper {

	/**
	 * Returns a list of nodes matching the expression, from the input source (url, file...).
	 * 
	 * @param inputSource any kind of XML based input source.
	 * @param expression an XPath expression.
	 * @return a list of nodes matching the expression.
	 * @throws XPathExpressionException
	 */
	public static NodeList getXPathNodes(InputSource inputSource, String expression) throws XPathExpressionException {
		XPath xpath = XPathFactory.newInstance().newXPath();
		NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
		return nodes;
	}
}
